package pailaidai.hc.com.mysvgdemo.activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.util.Log;
import android.view.View;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.zhy.autolayout.AutoLinearLayout;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import pailaidai.hc.com.mysvgdemo.MainActivity;
import pailaidai.hc.com.mysvgdemo.R;
import pailaidai.hc.com.mysvgdemo.event.EventActivity;
import pailaidai.hc.com.mysvgdemo.meetview.GlideRoundTransform;
import pailaidai.hc.com.mysvgdemo.meetview.MeetView;
import pailaidai.hc.com.mysvgdemo.util.VideoIntercept;

public class MeetFaceActivity extends AppCompatActivity implements View.OnClickListener {
    private MeetView meetface_meetview;
    private Button meetface_button;
    private ImageView meetface_image;
    private List<String> list = new ArrayList<>();
    private AutoLinearLayout animtion_layout;
    private ScaleAnimation scaleAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meet_face);
        initView();
        initListener();
    }

    private void initView() {
        transition2();
        list.add("1");
        list.add("2");
        list.add("3");
        meetface_meetview = (MeetView) findViewById(R.id.meetface_meetview);
        meetface_button = (Button) findViewById(R.id.meetface_button);
        meetface_image = (ImageView) findViewById(R.id.meetface_image);
        meetface_image.setImageBitmap(VideoIntercept.createBitmapFromVideoPath("http://img.multshows.com/test/MEETVIDEO/15265379714774JBD585H28",150,194));
        animtion_layout=findViewById(R.id.animtion_layout);
    }

    private void initListener() {
        meetface_meetview.setMeetViewListener(new MeetView.MeetViewListener() {
            @Override
            public void imageOnClickListener() {
                Toast.makeText(MeetFaceActivity.this, "点击了图片", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void addLyOnClickListener() {
                Toast.makeText(MeetFaceActivity.this, "点击了增加图片", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void editOnClickListener() {
                Toast.makeText(MeetFaceActivity.this, "点击了编辑图片", Toast.LENGTH_SHORT).show();
            }
        });
        meetface_button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.meetface_button:
//                MyItemAnimator myItemAnimator = new MyItemAnimator();
//                myItemAnimator.setAddDuration(1000);
//                myItemAnimator.setRemoveDuration(1000);
//                mRecyclerView.setItemAnimator(myItemAnimator);


//                setNotification();
//                setRemoteView();
//                transition();
//                list.add(0,"p");
//                Log.d("ssssss",""+list.toString());
//                list.remove(1);
//                Log.d("ssssss22",""+list.toString());
//                meetface_meetview.setUrl("http://img.multshows.com//test/MEETFACE/6.3602940817446381524903453817A6GZKRZ822");
//                Glide.with(getApplicationContext())
//                        .load("http://img.multshows.com//test//HEADIMG//1512466654423")
//                        .bitmapTransform(new GlideRoundTransform(MeetFaceActivity.this))
//                        .into(meetface_image);
//              startActivity(new Intent(MeetFaceActivity.this,CameraActivity.class));
                animtion_layout.startAnimation(scaleAnimation);

                break;
        }
    }

    private void transition() {
        TransitionDrawable drawable= (TransitionDrawable) meetface_image.getBackground();
        drawable.startTransition(5000);
    }
    private void transition2() {
        scaleAnimation=new ScaleAnimation(1.0f,1.0f,1.0f,0f);
        scaleAnimation.setDuration(3000);
        scaleAnimation.setFillAfter(true);
    }
    private void setNotification() {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
                .setContentTitle("您有一条新消息")
                .setContentText("高颜值有人加您为好友")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setContentIntent(pendingIntent)//点击通知栏跳转页面
                .setAutoCancel(true);//点击通知栏之后通知栏自动消失
        notificationManager.notify(1, notification.build());
    }

    private void setRemoteView() {
        Notification notification = new NotificationCompat.Builder(this)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setTicker("hello remoteView")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .build();
        Intent intent = new Intent(this, EventActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivities(this, 0, new Intent[]{intent}, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.activity_radar_layout);
        remoteViews.setTextViewText(R.id.radr_text, "Chapter_5");
        remoteViews.setImageViewResource(R.id.radr_image, R.drawable.dialog_loading);
        PendingIntent pendingIntent1 = PendingIntent.getActivity(this, 0, new Intent(this, CameraActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.radr_button, pendingIntent1);
        notification.contentView = remoteViews;
        notification.contentIntent = pendingIntent;
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(2, notification);


    }


    private void inspectPhoto() {
        File outputImage = new File(getExternalCacheDir(), "output_image.jpg");
        try {
            if (outputImage.exists()) {
                outputImage.delete();
            }
            outputImage.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (Build.VERSION.SDK_INT >= 24) {
//           String imageUrl= FileProvider.getUriForFile(MeetFaceActivity.this,"")

        }


    }


}
